<template>
	<u-datetime-picker
			:show="dateTime"
			v-model="time"
			confirmColor="#023F92"
			mode="date"
			:formatter="formatter"
			@cancel="dateTime = false"
			@confirm="confirm"
	></u-datetime-picker>
</template>

<script>
	export default {
		data() {
			return {
				dateTime: false,
				time: ''
			}
		},
		created() {
			this.time = this.$commonjs.getTime(new Date())
		},
		methods: {
			check() {
				this.dateTime = true
			},
			confirm(e) {
				const timeFormat = uni.$u.timeFormat
				this.$emit('getTime', timeFormat(e.value, 'yyyy-mm-dd'))
				this.dateTime = false
			},
			formatter(type, value) {
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				return value
			},
		}
	}
</script>

<style>
</style>